home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6592 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: C beginner needs your help ASAP
  5. Date: 18 Feb 1996 22:23 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <18FEB199622233346@erich.triumf.ca>
  9. References: <4g862f$p0b@risky.ecs.umass.edu> <4g8ahd$p8b@spectator.cris.com>
  10. NNTP-Posting-Host: ftp.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <4g8ahd$p8b@spectator.cris.com>, aubrey@concentric.net (Aubrey Harrison) writes...
  14. >In article <4g862f$p0b@risky.ecs.umass.edu>, sebag@ecs.umass.edu says...
  15. >>
  16. >>I am a new C programmmer who desperately needs help.
  17. >>I have been digging in the manuals for a way to do this but have still
  18. >>come out empty handed. Here is the problem: I want to open files in a while
  19. >>loop with different filenames. data0,data1,data2,data3, .. data1000 , ...
  20. >>I need to increment an integer each time around then convert it to a string
  21. >>and then somehow use strcat to combine the "data" with the integer string.
  22. >>After that use fopen(filename, "a");
  23. >        for(i=0; i<10; i++)
  24. >        {
  25. >                sprintf(buf,"%d",i);
  26. >                strcpy( filename,"data");
  27. >                strcat( filename, buf );
  28. >                strcat( filename, ".ext");
  29. >                printf( "%s\n", filename);
  30. >        }
  31.  
  32. This is a little easier, I think:
  33.     
  34.         FILE * fp;
  35.     char filename[143];
  36.     int i;
  37.     for(i = 0, i < 10; i++)
  38.         {
  39.         sprintf(filename, "data%d.ext", i);
  40.             if((fp = fopen(filename, "r")) == NULL)
  41.             /* report error or .... */
  42.         /* do stuff */
  43.         }
  44.  
  45. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  46. Internet: bennett@triumf.ca         | of one another only when one can be
  47. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  48. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  49. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.